home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-02 | 2.7 KB | 99 lines | [TEXT/AxoC] |
- LocalLanguage Pascal
- { -------------------------------------------------
- The following functions demonstrate various aspects of
- AxoCalculator's Pascal programming language.
-
- • To load all functions, choose "Select All"
- under the "Edit" menu, then press "enter".
-
- • To run a function, type its name followed
- by any parameters, then press "enter".
-
- • After the functions are loaded, this file does
- not need to remain open in order to use them.
-
- • Here are some examples of how to use the functions.
-
- BoxVolume (10,15,20)
- Factorial (10)
- RecursiveFact (10)
- SameBirthDateProb(25)
-
- --------------------------------------------------}
-
-
- { ---------------- RectArea -------------------
- This function calculates the area of a rectangle
- given its height and width.
- -------------------------------------------------}
- function RectArea (height, width)
- begin
- RectArea = height * width
- end
-
- { ---------------- BoxVolume ----------------------
- This function calculates the volume of a box
- given its height, width and depth. It calls the
- function RectArea to get the area of the bottom of
- the box, then multiplies the result by the box depth.
- -------------------------------------------------}
- function BoxVolume (height, width, depth)
- begin
- BoxVolume = RectArea (height, width) * depth
- end
-
- { ---------------- Factorial -------------------
- This function calculates the factorial of a number.
- -----------------------------------------------}
- function Factorial (number)
- Var
- f : Real
- i : Integer
- begin
- f = 1
- For i = 1 to Number do f = f * i
- Factorial = f
- end
-
-
- { ---------------- Factorial -------------------
- This function also calculates the factorial of a number,
- but it uses a recursive algorithm. This approach is
- inefficient, but demonstrates recursion.
- -----------------------------------------------}
- function RecursiveFact (number)
- begin
- if number > 1 then
- RecursiveFact = number * RecursiveFact (number - 1)
- else
- RecursiveFact = 1
- end
-
-
- { ---------------- SameBirthDateProb -------------------
- This function calculates the probability that two or more
- people in a group have the same birth date, given the
- number of people in the group. It works by calculating
- 1 - the probability that everyone in the group has a
- different birth date.
- -----------------------------------------------}
- function SameBirthDateProb (numberOfPeople)
- begin
- if (numberOfPeople < 2) then
- DiffBirthDateProb = 1
- else
- begin
- if (numberOfPeople > 365) then
- DiffBirthDateProb = 0
- else
- begin
- DiffBirthDateProb = 1
- For i = 2 to numberOfPeople do
- DiffBirthDateProb = DiffBirthDateProb * (366-i) / 365
- end
- end
- SameBirthDateProb = 1 - DiffBirthDateProb
- end
-
-
-